<?php
namespace models\repositories;
use Doctrine\ORM\EntityRepository;
use entities;
class DesaRepository extends EntityRepository {

	/**
     * @inheritdoc
     */
    public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
    {
        $orderBy = $orderBy === null ? array('id' => 'desc') : $orderBy;
        return parent::findBy($criteria, $orderBy, $limit, $offset);
    }
	
	public function findAll($orderBy=null){		
		return $this->findBy(array(), $orderBy);
	}
	
	public function findByDistrikIds($distrikIds){
		if (count($distrikIds) <= 0){
			return null;
		} 
		
		$distrikStr = implode(",",$distrikIds); 
		$qb = $this->_em->createQueryBuilder();
		$qb->select('Desa')
		   ->from('models\entities\Desa', 'Desa')
		   ->leftJoin('Desa.distrik', 'distrik');
		   
		   	 
		$whereClause = "distrik.id IN (".$distrikStr.")";   	 
		$qb->where($whereClause);
		$query = $qb->getQuery(); 
		//echo $query->getSQL();die();
		return $query->getResult();
	}
}

